package com.vcredit.creditcat.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.model.CustAccount;
import com.vcredit.creditcat.model.UserLogin;
import com.vcredit.creditcat.persistence.UserLoginMapper;
import com.vcredit.creditcat.persistence.base.CustAccountMapper;
import com.vcredit.creditcat.util.Utility;

/**
 * 
 **/
@Service
public class CustAccountService {
	@Autowired
	private CustAccountMapper mapper;
	@Autowired
	private UserLoginMapper userLoginmapper;

	public void insert(CustAccount obj) {
		mapper.insert(obj);
	}

	public void update(CustAccount obj) {
		mapper.update(obj);
	}

	public List<CustAccount> findAll() {
		return mapper.findAll();
	}

	public List<CustAccount> find(CustAccount obj) {
		return mapper.find(obj);
	}

	public UserLogin login(UserLogin obj) {
		return userLoginmapper.login(obj);
	}

	public UserLogin autoLogin(String deviceNo) {
		return userLoginmapper.autoLogin(deviceNo);
	}

	public CustAccount findById(Long accountId) {
		return mapper.findById(accountId);
	}
	
	public CustAccount findByCustId(Long custId) {
		List<CustAccount> list = mapper.findByCustId(custId);
		if(Utility.isNullOrEmpty(list)) {
			return null;
		}
		return list.get(0);
	}
}